import os
import time
import sys
from selenium.webdriver.common.by import By

from Base.base_action import BaseAction


class skinProtectRank(BaseAction):

    spr_btn = (By.XPATH, "//*[contains(@text, '护肤榜')]")  # 首页护肤榜按钮
    ranks = (By.ID, "org.c2h4.afei.beauty:id/iv_product")  # 产品的ID定位
    search_btn = (By.ID, "org.c2h4.afei.beauty:id/tool_search")  # 右上角搜索按钮
    swipe_right = (500, 1000, 200, 1000, 500)
    swipe_left = (500, 1000, 800, 1000, 500)

    def click_skin_pro_button(self):
        self.click_element(self.spr_btn)
        time.sleep(1)

    # 测试护肤榜的左右滑动功能
    def swipe_test(self):
        lenth = 13
        for _ in range(lenth):
            self.swipe(*self.swipe_right)
        for _ in range(lenth):
            self.swipe(*self.swipe_left)

    # 测试在护肤榜各个页面点击搜索按钮
    def search_test(self):
        lenth = 13
        for _ in range(lenth):
            self.swipe(*self.swipe_right)
            self.click_element(self.search_btn)
            time.sleep(1)
            for i in range(2):
                self.key_event(4)

    # 各板块产品点击
    def click_product(self):
        pass

    # 测试各功能
    def skin_pro_rank(self):
        self.click_skin_pro_button()
        self.swipe_test()
        self.search_test()
